<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<style type="text/css">
#add_shop_info .box p>label>span {
	display: inline-block;
	width: 80px;
	text-align: right;
}

#add_shop_info  .formBox {
	padding: 0;
}
#add_shop_info input[type='file']{
	display:none;
}

#add_shop_info .longWidth{
	width:410px;
}

#add_shop_info .box label {
	margin-left: 20px;
}
</style>
<div class="modal fade" id="add_shop_info" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document" style="width: 600px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">新增店仓</h4>
			</div>
			<form id="add_shop_form" enctype="multipart" class="form">
				<input type="hidden" name="firstid" id="firstid">
				<div class="box modal-body">
					<p>
						<label class="must">店仓代码</label>
						<input type="text" class="form-control" readonly placeholder="自动生成"></input>
						<label class="must">店仓名称</label>
						<input type="text" class="form-control" name="annexname"></input>
					</p>
					<p>
						<label class="must">联系方式</label>
						<input type="text" class="form-control" name="companytelephone"></input>
						<label class="must">状态</label>
						<select name="annexpath" class="form-control select">
							<option value="可用">可用</option>
							<option value="不可用">不可用</option>
						</select>
					</p>
					<p>
						<label class="must">地址</label>
						<input type="text" class="form-control" class="longWidth" name="address"></input>
					</p>
					<p>
						<label class="must">备注</label>
						<input type="text" class="form-control" class="longWidth" name="description"></input>
					</p>
				</div>
			</form>
			<div class="red" id="add_shop_msg" style="text-align:center;"></div>
			<div class="modal-footer">
				<button type="button" class="btn btn1" onclick="saveAddShop();">保存</button>
				<button type="button" class="btn btn2" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>
<script>

function addShop(){
	$('#add_shop_info :text').val("");
	$("#add_shop_info select").val("");
	$('#add_shop_info').modal('show');
}

function saveAddShop(){
	if(!validateAddForm()) return ;//校验
    var formData = $("#add_shop_form").serialize();  
	$.ajax({
		url:"<%=basePath %>shop/add.do",
		type:"post",
		async : false,
		dataType:"json",
		data : formData,
		success:function(data){
			if(data.result=="success"){
				$("#add_shop_msg").html("");
				$('#add_shop_info :text').val("");
				$("#add_shop_info select").val("");
				$('#add_shop_info').modal('hide');
				location.href=location.href;
			}else{
				$("#add_shop_msg").html("新增店仓失败：",data.error);
			}
		},
		error :function(){
			$("#add_shop_msg").html("新增店仓失败！")
		}
	});
}
//店仓管理校验
function validateAddForm(){
	
	if(!validateString("店仓名称","#add_shop_form [name='annexname']",30,false)){
		return false;
	} 
	
	if(!validateRegex("联系方式","#add_shop_form [name='companytelephone']",/^1[0-9]{10}$/,false)){
		return false;
	}
	
	 if(!validateSelect("状态","#add_shop_form [name='annexpath']",120,false)){
		return false;
	}
	
	if(!validateString("地址","#add_shop_form [name='address']",120,false)){
		return false;
	}
	
	if(!validateString("备注","#add_shop_form [name='description']",190,false)){
		return false;
	} 
	return true;
}



</script>